import axios from "axios"
import nProgress from "nprogress"
import 'nprogress/nprogress.css'

const request = axios.create({
  baseURL: '/api',
  timeout: 8000
})

request.interceptors.request.use((config) => {
  nProgress.start()
  // config 配置对象 其中有一个属性很重要 -> header 请求头
  return config
}, err => {
  return Promise.reject(err)
})

request.interceptors.response.use((res) => {
  nProgress.done()
  return res.data
}, err => {
  return Promise.reject(err)
})

export default request